package com.alibaba.citrus.cr.common.enums.ordercenter;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
public enum SalesOrderReasonEnum {

    CUSTOMER_ADD_ORDER("001", "客户加单"),
    CHEESE_ORDER_DOMESTIC_ORDER("002", "奶酪订单-内销订单"),
    DISTRIBUTE_TRIAL_DRINKS_ACCORDING_TO_NORMAL_SALES("003", "按正常销售发放试饮品"),
    CUSTOMER_RETURNS("004", "客户退货"),
    ERROR_IN_PRICE_MASTER_DATA_MAINTENANCE("005", "价格主数据维护有误"),
    CARGO_DAMAGE("006", "货损"),
    PURCHASE_GIVE("007", "买赠"),
    RETURN_OF_EXPIRED_PRODUCTS("A01", "过期品退货"),
    DAMAGED_RETURN("A02", "破损退货"),
    RETURN_AND_SUPPLEMENTARY_DISPLAY("A03", "退货补陈列"),
    RETURN_TO_MAKE_UP_INVENTORY_LOSS("A04", "退货补盘亏"),
    PRODUCT_QUALITY_RETURN("A05", "产品质量退货"),
    RETURN_COMPENSATION("A06", "退货补赔偿"),
    RETURN_WITH_WRONG_LOCK_CODE("A07", "锁码错码退货"),
    TEMPORARY_GOODS_RETURN("A08", "临期品退货"),
    RETURN_OF_LARGE_INVENTORY_GOODS("A09", "大库存商品退货"),
    RETURN_CONVERT_TO_TEST_DRINK("A10", "退货转试饮品"),
    OUTDOOR_SALES_RETURN("A11", "户外销售退货"),
    RETURN_FOR_OTHER_REASONS("A12", "其他原因退货"),
    MILK_CARD_EXCHANGE("A13", "奶卡兑换"),
    PATCHING("A14", "补残"),
    LOGISTICS_RETURN_POD_RETURN("A15", "物流退货(POD退货)"),
    OTHER_REPLENISHMENT("A16", "其他补货"),
    DONATE("A17", "捐赠"),
    PERIPHERAL_SYSTEM_RETURN_REQUEST("Y98", "外围系统退货请求"),
    SALES_OF_RAW_MATERIALS_SCRAP_OTHERS("Y99", "原材料/废品/其他等销售"),
    MENGNIU_HYPOTHERMIA("Z1", "蒙牛低温"),
    DANONE_LOW_TEMPERATURE("Z2", "达能低温");

    private final String code;
    private final String desc;

    SalesOrderReasonEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static SalesOrderReasonEnum of(String code) {
        return Arrays.stream(SalesOrderReasonEnum.values()).filter(source -> Objects.equals(code, source.getCode())).findFirst().orElse(null);
    }

    public static String descByCode(String code) {
        SalesOrderReasonEnum typeEnum = of(code);
        return Objects.nonNull(typeEnum) ? typeEnum.getDesc() : null;
    }

    public static List<String> codes() {
        return Arrays.stream(SalesOrderReasonEnum.values()).map(SalesOrderReasonEnum::getCode).collect(Collectors.toList());
    }
}
